﻿using System;
using System.Collections.Generic;
using System.Linq;
using Quadrant.domain.DB;
using Quadrant.domain.Helpers;
using Quadrant.domain.Models;

namespace Quadrant.domain.Services
{
    public class QuadrantServices : BaseServices
    {
        public QuadrantServices(QuadrantContext db)
            : base(db)
        {
        }

        public void InjectQuadrant(Guid userId, int quadrantModel)
        {
            var zoneTemplate = (new ZoneServices().GetQuadrantModel(quadrantModel));
            var zonesList = new List<Zone>(4);
            zonesList.AddRange(zoneTemplate.Select(zonet => new Zone
            {
                BoardZone = zonet.Item1,
                Name = zonet.Item2,
                Legend = zonet.Item3
            }));

            var newQuadrant = new Models.Quadrant
            {
                Id = Guid.NewGuid(),
                Name = "Unnamed",
                Owner = this.DB.QuadrantUsers.Single(p => p.Id == userId),
                Sticks = new List<Stick>
                            {
                                new Stick
                                {
                                    Name = "Example",
                                    Position = new BoardPosition(),
                                    Comments = "This is an example"
                                }
                            },
                Zones = zonesList
            };

            this.DB.Quadrants.Add(newQuadrant);
            this.DB.SaveChanges();
        }
    }
}
